﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WoChu.Infrastructure.Data;
using WoChu.Infrastructure.ModelCommmon;
using WoChu.WMS.Repository;
using WoChu.Infrastructure.Collection;

namespace Business.Service
{
    public class CommonDataService
    {
        CommonDataRepository _rep = new CommonDataRepository();

        public IEnumerable<dynamic> GetCellNolist()
        {
            SearchInfo search = new SearchInfo("distinct CELLNO", "lmlocation",
                "cellno in ('物料（非食材）','常温原料','冷藏原料','冷冻原料','冷冻原料LK5','蔬菜原料','水果原料','加工用原料','常温二级半成品','冷藏二级半成品','冷冻二级半成品','冷藏4度原料') ",
                "cellno desc");

            IEnumerable<dynamic> list = _rep.QueryList(search);
            return list;
        }
        public IEnumerable<dynamic> GetVenderList()
        {
            SearchInfo search = new SearchInfo("VENDERCODE CODE,VENDERNAME NAME", "vender", "status=1", "VENDERCODE");
            
            IEnumerable<dynamic> list = _rep.QueryList(search);
            return list;
        }

        public IEnumerable<dynamic> GetFlagList()
        {
            SearchInfo search = new SearchInfo("FieldValue CODE,LookUp NAME", "lookupitem", "lookupID='FLAG'", "");
            IEnumerable<dynamic> list = _rep.QueryList(search);
            return list;
        }

        /// <summary>
        /// 货位类型
        /// </summary>
        /// <returns></returns>
        public IEnumerable<dynamic> GetLocationTypeList()
        {
            SearchInfo search = new SearchInfo("FieldValue CODE,LookUp NAME", "lookupitem", "lookupID='LOCATIONTYPE'", "");
            IEnumerable<dynamic> list = _rep.QueryList(search);
            //string[] type = { "逻辑货位", "存储货位" };
            // var list = GetList(type);
            return list;
        }

        /// <summary>
        /// 仓库类别
        /// </summary>
        /// <returns></returns>
        public IEnumerable<dynamic> GetWarehouseList()
        {
            SearchInfo search = new SearchInfo("WAREHOUSECODE CODE,WAREHOUSENAME NAME", "WAREHOUSE");
            IEnumerable<dynamic> list = _rep.QueryList(search);
            return list;
        }
       
        /// <summary>
        /// 上架原因
        /// </summary>
        /// <returns></returns>
        public IEnumerable<dynamic> GetUpObjectTypeList()
        {
            string[] type = { "原料采购", "门店退货", "车间退货", "我厨退货", "青浦调拨", "其它" };
            var list = GetList(type);
            return list;
        }

        public IEnumerable<dynamic> GetDownObjectTypeList()
        {
            string[] type = { "门店出货", "领料耗用", "报损", "退货", "青浦调拨", "其它" };
            var list = GetList(type);
            return list;
        }

        public IEnumerable<dynamic> GetDownTypeList()
        {
            string[] type = { "指令下架", "盲扫下架" };
            var list = GetList(type);
            return list;
        }

        /// <summary>
        /// 是否启用
        /// </summary>
        /// <returns></returns>
        public IEnumerable<dynamic> GetStatusList()
        {
            string[] type = { "启用", "停用" };
            string[] code = { "1", "0" };
            var list = GetList(type,code);
            return list;
        }

        /// <summary>
        /// 商品状态
        /// </summary>
        /// <returns></returns>
        public IEnumerable<dynamic> GetGoodsStatusList()
        {
            string[] type = { "有效", "无效" };
            string[] code = { "1", "9" };
            var list = GetList(type, code);
            return list;
        }

        public IEnumerable<dynamic> GetList(string[] types,string[] codes=null)
        {
            var list = types.Select(s =>
            {
                dynamic obj;
                obj = new ExpandoObject();
                obj.NAME = s;
                if (codes != null)
                {
                    int i = types.IndexOf<string>(s);
                    obj.CODE = codes[i];
                }
                
                return obj;
            });
            return list;
        }
        /// <summary>
        /// 下架指令类型
        /// </summary>
        /// <returns></returns>
        public IEnumerable<dynamic> GetOffShelvesTypeList()
        {
            SearchInfo search = new SearchInfo("FieldValue CODE,LookUp NAME", "lookupitem", "lookupID='OFFSHELVESTYPE'", "");
            IEnumerable<dynamic> list = _rep.QueryList(search);
            return list;
        }
    }
}
